﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace ConsoleApplication1
{
    class connection
    {
        TcpListener server;
       public string recive()
        {
            TcpListener server = new TcpListener(6711);
            server.Start();

            Console.Write("start");
            TcpClient newclint = server.AcceptTcpClient();
            Console.Write("read ");

            NetworkStream ns = newclint.GetStream();

            byte[] bytesfrom = new byte[(int)newclint.ReceiveBufferSize];
            ns.Read(bytesfrom, 0, (int)newclint.ReceiveBufferSize);

            string data = System.Text.Encoding.ASCII.GetString(bytesfrom);

            data = data.Substring(0, data.Length);

            Console.WriteLine(data);

            ns.Flush();
            //newclint.Close();
            //server.Stop();
            Console.WriteLine("exit");
            return data;
        }

       public void send(string data)
       {
           TcpClient server;
        //   try
           {
               server = new TcpClient("127.0.0.1", 6711);
               Console.WriteLine("okeeh ");

               NetworkStream ns = server.GetStream();
               byte[] outstream = System.Text.Encoding.ASCII.GetBytes(data);

               ns.Write(outstream, 0, outstream.Length);
          //     ns.Flush();
               server.Close();

           }
           //catch (SocketException e)
           //{
               
           //    Console.WriteLine("mosh rady yab3t ");
           //    Console.WriteLine(e.ToString());
           //}

       }
    }
}
